package com.tanhua.server.controller;

import com.tanhua.model.vo.CountsVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.interceptor.UserHolder;
import com.tanhua.server.service.SettingsService;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;
    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 查询通用设置
     */
    @GetMapping("/settings")
    public ResponseEntity settings() {
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }

    /**
     * 设置陌生人问题
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map) {
        //获取参数
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 通知设置
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map) {
        //获取参数
        settingsService.saveSettings(map);
        return ResponseEntity.ok(null);
    }

    /**
     * 分页查询黑名单列表
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        //1、调用service查询
        PageResult pr = settingsService.blacklist(page, size);
        //2、构造返回
        return ResponseEntity.ok(pr);
    }

    /**
     * 取消黑名单
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId) {
        settingsService.deleteBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }


    /**
     * app互相喜欢，喜欢，粉丝 - 统计
     *
     * @return
     */
    @GetMapping("/counts")
    public ResponseEntity counts() {
        Long userId = UserHolder.getUserId();
        CountsVo vo = settingsService.lovecounts(userId);
        return ResponseEntity.ok(vo);

    }
    /**
     * 粉丝-喜欢
     * 在列表页面查看喜欢我的用户（粉丝），可以对粉丝进行喜欢
     *
     * @param likeUserId
     * @return
     */
    @PostMapping("/fans/{uid}")
    public ResponseEntity likefans(@PathVariable("uid") Long likeUserId) {

        tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);

    }

    /**
     * 喜欢-取消
     * 对于已喜欢的用户，可以进行取消喜欢
     *
     * @param likeUserId
     * @return
     */
    @DeleteMapping("/like/{uid}")
    public ResponseEntity deletelike(@PathVariable("uid") Long likeUserId) {

        settingsService.deleteLike(likeUserId);
        return ResponseEntity.ok(null);
    }


}
